package com.fqy.thread02.procon01;

/**
 * User: fqy
 * Date: 2021/9/1
 * Time: 11:05
 * Describe:
 *  有一个初始值为0的变量 有俩个线程对该变量操作
 *  实现一个线程对变量加1 实现一个线程对变量减1 交替10次
 *  1.高内聚低耦合  线程 操作 资源类
 *  2.判断  干活  通知
 *  3.防止线程的虚假唤醒 判断时推荐使用while
 */
public class ProduceAndConsumerDemo {

    public static void main(String[] args) {
        AirCondition airCondition = new AirCondition();

        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    airCondition.increament();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1").start();

        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    airCondition.decreament();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t2").start();

        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    airCondition.increament();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t3").start();

        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    airCondition.decreament();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t4").start();
    }

}
